# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'Unity-iPhone' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Unity-iPhone

  target 'Unity-iPhone Tests' do
    inherit! :search_paths
    # Pods for testing
  end

end

target 'UnityFramework' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  pod 'MJExtension'
  pod 'AFNetworking'
  pod 'YYCache'
  pod 'CocoaLumberjack'
  pod 'MMKV'
  pod 'MyLayout'
  
  # google 广告
  pod 'Google-Mobile-Ads-SDK'
  pod 'GoogleUserMessagingPlatform'
  
  # 谷歌登录
  pod 'GoogleSignIn'
  # Facebook 登录
  pod 'FBSDKLoginKit'
  
  pod 'SVProgressHUD'
  
  pod 'Adjust'
  
  pod 'FirebaseAnalytics'
  
  pod 'FirebaseCrashlytics'
  
  pod 'ThinkingSDK'
  
  
end


post_install do |installer|
    installer.generated_projects.each do |project|
        project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
            end
        end
    end
    
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          xcconfig_path = config.base_configuration_reference.real_path
          xcconfig = File.read(xcconfig_path)
          xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
          File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
        end
    end
    
    applicationTargets = [
            'Pods-Unity-iPhone',
        ]
    
        libraryTargets = [
            'Pods-UnityFramework',
        ]
    
        embedded_targets = installer.aggregate_targets.select { |aggregate_target|
            libraryTargets.include? aggregate_target.name
        }
    
        embedded_pod_targets = embedded_targets.flat_map { |embedded_target| embedded_target.pod_targets }
        host_targets = installer.aggregate_targets.select { |aggregate_target|
            applicationTargets.include? aggregate_target.name
        }
    
        # We only want to remove pods from Application targets, not libraries
        host_targets.each do |host_target|
            host_target.xcconfigs.each do |config_name, config_file|
                host_target.pod_targets.each do |pod_target|
                    if embedded_pod_targets.include? pod_target
                        pod_target.specs.each do |spec|
                            if spec.attributes_hash['ios'] != nil
                                frameworkPaths = spec.attributes_hash['ios']['vendored_frameworks']
                                else
                                frameworkPaths = spec.attributes_hash['vendored_frameworks']
                            end
    
                            if frameworkPaths != nil
                                frameworkNames = Array(frameworkPaths).map(&:to_s).map do |filename|
                                    extension = File.extname filename
                                    File.basename filename, extension
                                end
                                frameworkNames.each do |name|
                                    puts "Removing #{name} from OTHER_LDFLAGS of target #{host_target.name}"
                                    config_file.frameworks.delete(name)
                                end
                            end
                        end
                    end
                end
    
                xcconfig_path = host_target.xcconfig_path(config_name)
                config_file.save_as(xcconfig_path)
    
            end
        end
end
